package com.ruoyi.user.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.user.domain.UserCoupon;
import com.ruoyi.user.mapper.UserCouponMapper;
import com.ruoyi.user.service.IUserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 持有优惠卷Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-10
 */
@Service
public class UserCouponServiceImpl implements IUserCouponService {
    @Autowired
    private UserCouponMapper userCouponMapper;

    /**
     * 查询持有优惠卷
     *
     * @param id 持有优惠卷主键
     * @return 持有优惠卷
     */
    @Override
    public UserCoupon selectUserCouponById(Long id) {
        return userCouponMapper.selectUserCouponById(id);
    }

    /**
     * 查询持有优惠卷列表
     *
     * @param userCoupon 持有优惠卷
     * @return 持有优惠卷
     */
    @Override
    public List<UserCoupon> selectUserCouponList(UserCoupon userCoupon) {
        return userCouponMapper.selectUserCouponList(userCoupon);
    }

    /**
     * 新增持有优惠卷
     *
     * @param userCoupon 持有优惠卷
     * @return 结果
     */
    @Transactional(rollbackFor = RuntimeException.class)
    @Override
    public int insertUserCoupon(UserCoupon userCoupon) {

        userCoupon.setCreateTime(DateUtils.getNowDate());
        return userCouponMapper.insertUserCoupon(userCoupon);
    }

    /**
     * 修改持有优惠卷
     *
     * @param userCoupon 持有优惠卷
     * @return 结果
     */
    @Override
    public int updateUserCoupon(UserCoupon userCoupon) {
        userCoupon.setCouponType(0);
        userCoupon.setUpdateTime(DateUtils.getNowDate());
        return userCouponMapper.updateUserCoupon(userCoupon);
    }

    /**
     * 批量删除持有优惠卷
     *
     * @param ids 需要删除的持有优惠卷主键
     * @return 结果
     */
    @Override
    public int deleteUserCouponByIds(Long[] ids) {
        return userCouponMapper.deleteUserCouponByIds(ids);
    }

    /**
     * 删除持有优惠卷信息
     *
     * @param id 持有优惠卷主键
     * @return 结果
     */
    @Override
    public int deleteUserCouponById(Long id) {
        return userCouponMapper.deleteUserCouponById(id);
    }
}
